import numpy as np
import pandas as pd

path = "./data/Big-Class.xls"

data_df = pd.read_excel(path)
data_df[['age','height','weight']].describe()

import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']= False

data_df[['age','height','weight']].boxplot()
plt.savefig("3.3-boxplot.png")

high_df = data_df[['height']]

content_dict = {
    'error_value':[[1,172],[1.1,170]],
    'up_limit':[[1.03,144],[1.2,144]],
    'down_limit':[[1.03,65],[1.2,65]],
    '$Q_{2}$':[[1.03,105],[1.2,105]],
    '$Q_{1}$':[[1.03,91.75],[1.2,91.75]],
    '$Q_{3}$':[[1.03,115.25],[1.2,115.25]]}

high_df.boxplot(notch = True, whis = 1.5)
plt.grid()

for key, value in content_dict.items():
    plt.annotate(r'{}'.format(key),xy = tuple(value[0]),xytext = tuple(value[1]),
                                        color = '#090909', arrowprops = 
                                        dict(arrowstyle='->',connectionstyle = 
                                        'arc3, rad = 0.1',color = 'red'))

data_df['gender_value']=data_df['gender'].map(lambda x:1 if x == 'M' else 2)
data_df[['gender_value','age','weight','height']].hist(figsize = (6,6))

scatter_dict = {
    0:[['age','height'],[data_df['age'],data_df['height']]],
    1:[['age','weight'],[data_df['age'],data_df['weight']]],
    2:[['weight','height'],[data_df['weight'],data_df['height']]],}

fig, axes = plt.subplots(1,3,figsize = (14,4))
for key, value in scatter_dict.items():
    axes[key].scatter(value[1][0],value[1][1],c=data_df['gender_value'])
    axes[key].set_xlabel('{}'.format(value[0][0]))
    axes[key].set_ylabel('{}'.format(value[0][-1]))
    axes[key].grid(True, linestyle = '-.')
plt.savefig("3.6-scatter.png")

#from numpy import dot, transpose

#data_copy_df['constant']=1
#x_arr = data_copy_df[['age','weight']].values
#y_arr = data_copy_df[['height']].values

#left_value = inv(dot(transpose(x_arr),x_arr))
#right_value = dot(transpose(x_arr),y_arr)

#coeff_arr = dot(left_value,right_value)
#print(coeff_arr)
